package janino;

import org.codehaus.commons.compiler.CompilerFactoryFactory;
import org.codehaus.commons.compiler.IExpressionEvaluator;
import org.codehaus.janino.ExpressionEvaluator;
import org.codehaus.janino.ScriptEvaluator;

public class JaninoTester02 {

    public static void main(String[] args) {
        try {
            String express = "(count + 2) * total";
			IExpressionEvaluator evaluator = CompilerFactoryFactory.getDefaultCompilerFactory().newExpressionEvaluator();
			evaluator.setParameters(new String[]{"total", "count"}, new Class[]{double.class, int.class});
			evaluator.cook(express);
			evaluator.setExpressionType(Double.class);
			Object[] arguments = {new Double(120), new Integer(10)};
			Object res = evaluator.evaluate(arguments);
            System.out.println(express + "=" + res);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}